package models;

import java.util.List;

import javax.persistence.Entity;

import ch.bfh.abcm.rems.sensors.tinkerforge.TFSensorType;
import play.db.jpa.Model;

/**
 * @author Christian
 * 
 */
@Entity
public class SensorConfig extends Model {

    private TFSensorType sensorType;
    private String uid;
    private String measurementPointIP;
    private String measurementPointUID;

    protected SensorConfig() {
    }

    public SensorConfig(TFSensorType sensorType, String uid, String measurementPointIP, String measurementPointUID) {
        this.sensorType = sensorType;
        this.uid = uid;
        this.measurementPointIP = measurementPointIP;
        this.measurementPointUID = measurementPointUID;
    }

    public TFSensorType getSensorType() {
        return sensorType;
    }

    public void setSensorType(TFSensorType sensorType) {
        this.sensorType = sensorType;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getMeasurementPointIP() {
        return measurementPointIP;
    }

    public void setMeasurementPointIP(String measurementPointIP) {
        this.measurementPointIP = measurementPointIP;
    }

    public String getMeasurementPointUID() {
        return measurementPointUID;
    }

    public void setMeasurementPointUID(String measurementPointUID) {
        this.measurementPointUID = measurementPointUID;
    }

    public static List<TFSensorType> getConfiguredSensorTypeList() {
        return find("SELECT c.sensorType FROM SensorConfig c GROUP BY c.sensorType").fetch();
    }
    
    public static List<SensorConfig> getMeasurementPointsByObject() {
        return find("SELECT c FROM SensorConfig c GROUP BY c.measurementPointIP").fetch();
    }
    
    public static List<String> getMeasurementPoints() {
        return find("SELECT c.measurementPointIP FROM SensorConfig c GROUP BY c.measurementPointIP").fetch();
    }

    public static List<SensorConfig> getSensors(String measurementPointIP) {
        return find("SELECT c FROM SensorConfig c WHERE c.measurementPointIP=?1", measurementPointIP).fetch();
    }

    @Override
    public String toString() {
        return "SystemConfig [sensorType=" + sensorType + ", uid=" + uid + ", measurementPointIP=" + measurementPointIP
                + ", measurementPointUID=" + measurementPointUID + "]";
    }
}